package com.zx.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * sentinel授权
 * @author jack.wu
 * @version 1.0
 * @date 2020-03-09
 */
//@Component
public class RequestOriginParseDefinition implements RequestOriginParser {

    /**
     * 定义区分来源：本质作用是通过request域获取来源标识然后交给流控应用 位置进行匹配
     *
     * @param request request
     * @return serviceName
     */
    @Override
    public String parseOrigin(HttpServletRequest request) {
        String serviceName = request.getParameter("serviceName");
        if (StringUtils.isEmpty(serviceName)) {
            throw new RuntimeException("ServiceName is Empty");
        }
        return serviceName;
    }
}
